# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils
DESCRIPTION="Daemon that responds to network cables being plugged in and out."
HOMEPAGE="http://www.red-bean.com/~bos/"
SRC_URI="http://www.red-bean.com/~bos/netplug/${P}.tar.bz2"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="x86"
IUSE=""
DEPEND=">=iproute2-2.4.7"

hax_bitkeeper() {
	# the makefiles have support for bk ...
	# basically we have to do this or bk will try to write
	# to files in /opt/bitkeeper causing sandbox violations ;(
	mkdir ${T}/fakebin
	echo "#!/bin/sh"$'\n'"exit 1" > ${T}/fakebin/bk
	chmod a+x ${T}/fakebin/bk
	export PATH="${T}/fakebin:${PATH}"
}

src_unpack() {
	unpack ${A}
	cd ${S}
	epatch ${FILESDIR}/Makefile.patch
	epatch ${FILESDIR}/netplug.patch
	epatch ${FILESDIR}/netplugd.8.patch
	epatch ${FILESDIR}/rc.netplugd.patch
}

src_compile() {
	hax_bitkeeper
	emake || die "emake failed"
}

src_install() {
	make \
		prefix=${D}/ \
		mandir=${D}/usr/share/man \
		infodir=${D}/usr/share/info \
		libdir=${D}/usr/$(get_libdir) \
		etcdir=${D}/etc \
		initdir=${D}/etc/init.d \
		scriptdir=${D}/etc/conf.d \
		install || die
}
